Law of Demeter
The Law of Demeter is a guideline for minimizing knowledge between objects. A method should generally communicate with its immediate collaborators rather than navigating through long chains of unrelated objects. The common symptom is code such as order.getCustomer().getAddress().getCity().getName(). Such chains expose internal object structure and increase coupling. The principle is a heuristic rather than an absolute prohibition on method chaining.
Prefer interactions with immediate collaborators.
Avoid excessive knowledge of another object's internal structure.
Long navigation chains often indicate misplaced responsibility.
The principle reduces coupling and makes refactoring safer.
Not every fluent API chain violates the spirit of Demeter.